﻿Imports Control_Vuelos_BE
Imports System.Data.SqlClient

Public Class V_ReservaADO
    ReadOnly MiConexion As New ConexionADO()
    ReadOnly cnx As New SqlConnection(MiConexion.GetCnx)
    Dim cmd As New SqlCommand
    Dim lExito As Boolean

    Public Function CargarPrioridad(ByVal sTipo As String) As String
        Dim dtr As SqlDataReader
        Dim sPrioridad As String = ""
        Try
            cmd.Connection = cnx
            cmd.CommandType = CommandType.Text
            cmd.CommandText = String.Format("SELECT codPrioridad FROM dbo.M_TipoPasajero WHERE (CodTipoPasajero='{0}')", sTipo)
            cnx.Open()
            dtr = cmd.ExecuteReader
            If dtr.HasRows = True Then
                dtr.Read()
                sPrioridad = dtr(0)
            End If
        Catch x As SqlException
            MsgBox("Reserva (CargarPrioridad) --> " & x.Message, MsgBoxStyle.Critical)
        Finally
            If cnx.State = ConnectionState.Open Then
                cnx.Close()
            End If
        End Try
        Return sPrioridad
    End Function


    Public Function CrearReserva(ByVal rBE As V_ReservaBE) As Boolean
        cmd.Connection = cnx
        cmd.CommandType = CommandType.StoredProcedure
        cmd.CommandText = "pr_InsertarReserva"
        Try
            With rBE
                cmd.Parameters.Add(New SqlParameter("@pdFchReserva", SqlDbType.DateTime))
                cmd.Parameters("@pdFchReserva").Value = .FchReserva
                cmd.Parameters.Add(New SqlParameter("@psTipPasajero", SqlDbType.VarChar, 1))
                cmd.Parameters("@psTipPasajero").Value = .TipPasajero
                cmd.Parameters.Add(New SqlParameter("@psNomContacto", SqlDbType.VarChar, 7))
                cmd.Parameters("@psNomContacto").Value = .NomContacto
                cmd.Parameters.Add(New SqlParameter("@pdFchViaje", SqlDbType.DateTime))
                cmd.Parameters("@pdFchViaje").Value = .FchViaje
                cmd.Parameters.Add(New SqlParameter("@pnPsoPasajero", SqlDbType.Decimal))
                cmd.Parameters("@pnPsoPasajero").Value = .PsoPasajero
                cmd.Parameters.Add(New SqlParameter("@psNroPrioridad", SqlDbType.VarChar, 1))
                cmd.Parameters("@psNroPrioridad").Value = .NroPrioridad
                cmd.Parameters.Add(New SqlParameter("@psMotivoViaje", SqlDbType.VarChar, 3))
                cmd.Parameters("@psMotivoViaje").Value = .MotivoViaje
                cmd.Parameters.Add(New SqlParameter("@psCodAnalisis", SqlDbType.VarChar, 7))
                cmd.Parameters("@psCodAnalisis").Value = .CodAnalisis
                cmd.Parameters.Add(New SqlParameter("@psCodComunidad", SqlDbType.VarChar, 7))
                cmd.Parameters("@psCodComunidad").Value = IIf(.CodComunidad Is String.Empty, "0000000", .CodComunidad)
                cmd.Parameters.Add(New SqlParameter("@psCodCentroCosto", SqlDbType.VarChar, 7))
                cmd.Parameters("@psCodCentroCosto").Value = .CodCentroCosto
                cmd.Parameters.Add(New SqlParameter("@pnPsoEquipajePasajero", SqlDbType.Decimal))
                cmd.Parameters("@pnPsoEquipajePasajero").Value = .PsoEquipajePasajero
                cmd.Parameters.Add(New SqlParameter("@psEstadoReserva", SqlDbType.VarChar, 1))
                cmd.Parameters("@psEstadoReserva").Value = .EstadoReserva
                cmd.Parameters.Add(New SqlParameter("@plFlgRequisitos", SqlDbType.Bit))
                cmd.Parameters("@plFlgRequisitos").Value = .FlgRequisitos
                cmd.Parameters.Add(New SqlParameter("@pdFchRetorno", SqlDbType.DateTime))
                cmd.Parameters("@pdFchRetorno").Value = .FchRetorno
                cmd.Parameters.Add(New SqlParameter("@plFlgPermiso", SqlDbType.Bit))
                cmd.Parameters("@plFlgPermiso").Value = .FlgPermiso
                If .CodPasajero > 0 Then
                    cmd.Parameters.Add(New SqlParameter("@pnCodPasajero", SqlDbType.Int))
                    cmd.Parameters("@pnCodPasajero").Value = .CodPasajero
                End If
                cmd.Parameters.Add(New SqlParameter("@psCodLugarReserva", SqlDbType.VarChar, 3))
                cmd.Parameters("@psCodLugarReserva").Value = .CodLugarReserva
                cmd.Parameters.Add(New SqlParameter("@psNroBoleta", SqlDbType.VarChar, 20))
                cmd.Parameters("@psNroBoleta").Value = .NroBoleta
                cmd.Parameters.Add(New SqlParameter("@psObsReserva", SqlDbType.Text))
                cmd.Parameters("@psObsReserva").Value = .ObsReserva
                cmd.Parameters.Add(New SqlParameter("@pnPctCentroCosto", SqlDbType.Int))
                cmd.Parameters("@pnPctCentroCosto").Value = .PctCentroCosto
                cmd.Parameters.Add(New SqlParameter("@psCodCentroCosto2", SqlDbType.VarChar, 7))
                cmd.Parameters("@psCodCentroCosto2").Value = .CodCentroCosto2
                cmd.Parameters.Add(New SqlParameter("@plFlgSctrSalud", SqlDbType.Bit))
                cmd.Parameters("@plFlgSctrSalud").Value = .FlgSctrSalud
                cmd.Parameters.Add(New SqlParameter("@plFlgSctrPension", SqlDbType.Bit))
                cmd.Parameters("@plFlgSctrPension").Value = .FlgSctrPension
                cmd.Parameters.Add(New SqlParameter("@plFlgExamenActitud", SqlDbType.Bit))
                cmd.Parameters("@plFlgExamenActitud").Value = .FlgExamenActitud
                cmd.Parameters.Add(New SqlParameter("@plFlgAsumeMarsa", SqlDbType.Bit))
                cmd.Parameters("@plFlgAsumeMarsa").Value = .FlgAsumeMarsa
                cmd.Parameters.Add(New SqlParameter("@plFlgPrestamo", SqlDbType.Bit))
                cmd.Parameters("@plFlgPrestamo").Value = .FlgPrestamo
                cmd.Parameters.Add(New SqlParameter("@plFlgResRetorno", SqlDbType.Bit))
                cmd.Parameters("@plFlgResRetorno").Value = .FlgResRetorno
                cmd.Parameters.Add(New SqlParameter("@plFlgNew", SqlDbType.Bit))
                cmd.Parameters("@plFlgNew").Value = .FlgNew
                cmd.Parameters.Add(New SqlParameter("@plFlgResPasajero", SqlDbType.Bit))
                cmd.Parameters("@plFlgResPasajero").Value = .FlgResPasajero
            End With
            cnx.Open()
            cmd.ExecuteNonQuery()
            lExito = True
        Catch x As SqlException
            MsgBox("Reserva (pr_InsertarReserva) --> " & x.Message, MsgBoxStyle.Critical)
            lExito = False
        Finally
            If cnx.State = ConnectionState.Open Then
                cnx.Close()
            End If
            cmd.Parameters.Clear()
        End Try
        Return lExito
    End Function

    Public Function EliminarReserva(ByVal sCodr As Integer) As Boolean
        cmd.Connection = cnx
        cmd.CommandType = CommandType.StoredProcedure
        cmd.CommandText = "pr_EliminarReserva"
        Try
            cmd.Parameters.Add(New SqlParameter("@pnCodReserva", SqlDbType.Int))
            cmd.Parameters("@pnCodReserva").Value = sCodr
            cnx.Open()
            cmd.ExecuteNonQuery()
            lExito = True
        Catch x As SqlException
            MsgBox("Reserva (pr_EliminarReserva) --> " & x.Message, MsgBoxStyle.Critical)
            lExito = False
        Finally
            If cnx.State = ConnectionState.Open Then
                cnx.Close()
            End If
            cmd.Parameters.Clear()
        End Try
        Return lExito
    End Function

    Public Function ListarReserva(ByVal sFiltro As String) As DataTable
        Dim dt As New DataTable
        Dim sql As String = "SELECT r.CodReserva,r.FchReserva,r.FchViaje,r.FchRetorno,lr.NomLugar as Lugar,p.NroDocumentoId as dni" & _
                            ",p.AppPasajero+' '+p.ApmPasajero+', '+p.NomPasajero as Pasajero,CASE WHEN r.EstadoReserva = '1' THEN 'Stand By' " & _
                            " WHEN r.EstadoReserva = '2' THEN 'Habilitado'  WHEN r.EstadoReserva = '3' THEN 'Programado' WHEN r.EstadoReserva = '4' THEN 'Arrivado' " & _
                            " WHEN r.EstadoReserva = '5' THEN 'Perdida de vuelo' WHEN r.EstadoReserva = '9' THEN 'Anulado' " & _
                            " ELSE 'No hay reserva' END EstadoReserva, r.CodAnalisis,a.Desanl,p.CodLugarResidencia,lugar.NomLugar  " & _
                            " FROM dbo.V_Reserva r inner join dbo.M_Pasajero p on r.CodPasajero=p.CodPasajero inner join dbo.M_lugar lr on r.CodLugarReserva=lr.CodLugar " & _
                            " inner join dbo.Analisis a on r.CodAnalisis = a.codanl left join (SELECT CodLugar,NomLugar from M_Lugar where TipLugar='R') lugar on p.CodLugarResidencia  = lugar.CodLugar "

        Dim scriterio As String = IIf(sFiltro.Trim() = "", "", " Where " & Trim(sFiltro))
        Try
            cnx.Open()
            Using da As New SqlDataAdapter(sql & scriterio, cnx)
                da.Fill(dt)
            End Using
            cnx.Close()
            Return dt
        Catch myException As Exception
            MsgBox("Listar Reserva --> " & myException.Message, MsgBoxStyle.Critical)
            Return Nothing
        End Try
    End Function

    Public Function ListarReservas(ByVal p_tippasajero As String, ByVal p_estadoreserva As String, ByVal p_lugarreserva As String) As DataTable
        Try
            Dim cn As New SqlConnection(MiConexion.GetCnx)
            Using cn
                Dim cmd As New SqlCommand("sp_Lista_Reservas", cn)
                Using cmd
                    cmd.CommandType = Data.CommandType.StoredProcedure
                    cmd.Parameters.Add("@p_tippasajero", SqlDbType.Char, 1)
                    cmd.Parameters("@p_tippasajero").Value = p_tippasajero.Trim
                    cmd.Parameters.Add("@p_estadoreserva", SqlDbType.Char, 1)
                    cmd.Parameters("@p_estadoreserva").Value = p_estadoreserva.Trim
                    cmd.Parameters.Add("@p_lugarreserva", SqlDbType.Char, 3)
                    cmd.Parameters("@p_lugarreserva").Value = p_lugarreserva.Trim
                    Dim da As SqlDataAdapter = New SqlDataAdapter(cmd)
                    Dim dt As DataTable = New DataTable("Reservas")
                    da.Fill(dt)
                    Return dt
                End Using
            End Using
        Catch myException As Exception
            MsgBox("V_ReservaADO (ListarReservas) --> " & myException.Message, MsgBoxStyle.Critical)
            Return Nothing
        End Try
    End Function

    Public Function ListarReservasBuscar() As DataTable
        Try
            Dim cn As New SqlConnection(MiConexion.GetCnx)
            Using cn
                Dim cmd As New SqlCommand("sp_Lista_Reservas_Buscar", cn)
                Using cmd
                    cmd.CommandType = Data.CommandType.StoredProcedure
                    Dim da As SqlDataAdapter = New SqlDataAdapter(cmd)
                    Dim dt As DataTable = New DataTable("Reservas")
                    da.Fill(dt)
                    Return dt
                End Using
            End Using
        Catch myException As Exception
            MsgBox("V_ReservaADO (ListarReservasBuscar) --> " & myException.Message, MsgBoxStyle.Critical)
            Return Nothing
        End Try
    End Function

    Public Function ListarReservasVarios(ByVal p_tippasajero As String, ByVal p_estadoreserva As String, ByVal p_lugarreserva As String) As DataTable
        Try
            Dim cn As New SqlConnection(MiConexion.GetCnx)
            Using cn
                Dim cmd As New SqlCommand("sp_Lista_Reservas_Varios", cn)
                Using cmd
                    cmd.CommandType = Data.CommandType.StoredProcedure
                    cmd.Parameters.Add("@p_tippasajero", SqlDbType.Char, 1)
                    cmd.Parameters("@p_tippasajero").Value = p_tippasajero.Trim
                    cmd.Parameters.Add("@p_estadoreserva", SqlDbType.Char, 1)
                    cmd.Parameters("@p_estadoreserva").Value = p_estadoreserva.Trim
                    cmd.Parameters.Add("@p_lugarreserva", SqlDbType.Char, 3)
                    cmd.Parameters("@p_lugarreserva").Value = p_lugarreserva.Trim

                    Dim da As SqlDataAdapter = New SqlDataAdapter(cmd)
                    Dim dt As DataTable = New DataTable("Reservas")
                    da.Fill(dt)
                    Return dt
                End Using
            End Using
        Catch myException As Exception
            MsgBox("V_ReservaADO (ListarReservasVarios) --> " & myException.Message, MsgBoxStyle.Critical)
            Return Nothing
        End Try
    End Function

    Public Function ModificarReserva(ByVal rBE As V_ReservaBE) As Boolean
        cmd.Connection = cnx
        cmd.CommandType = CommandType.StoredProcedure
        cmd.CommandText = "pr_ModificarReserva"
        Try
            With rBE
                cmd.Parameters.Add(New SqlParameter("@pnCodReserva", SqlDbType.Int))
                cmd.Parameters("@pnCodReserva").Value = .CodReserva
                cmd.Parameters.Add(New SqlParameter("@pdFchReserva", SqlDbType.DateTime))
                cmd.Parameters("@pdFchReserva").Value = .FchReserva
                cmd.Parameters.Add(New SqlParameter("@psTipPasajero", SqlDbType.VarChar, 1))
                cmd.Parameters("@psTipPasajero").Value = .TipPasajero
                cmd.Parameters.Add(New SqlParameter("@psNomContacto", SqlDbType.VarChar, 7))
                cmd.Parameters("@psNomContacto").Value = .NomContacto
                cmd.Parameters.Add(New SqlParameter("@pdFchViaje", SqlDbType.DateTime))
                cmd.Parameters("@pdFchViaje").Value = .FchViaje
                cmd.Parameters.Add(New SqlParameter("@pnPsoPasajero", SqlDbType.Decimal))
                cmd.Parameters("@pnPsoPasajero").Value = .PsoPasajero
                cmd.Parameters.Add(New SqlParameter("@psNroPrioridad", SqlDbType.VarChar, 1))
                cmd.Parameters("@psNroPrioridad").Value = .NroPrioridad
                cmd.Parameters.Add(New SqlParameter("@psMotivoViaje", SqlDbType.VarChar, 3))
                cmd.Parameters("@psMotivoViaje").Value = .MotivoViaje
                cmd.Parameters.Add(New SqlParameter("@psCodAnalisis", SqlDbType.VarChar, 7))
                cmd.Parameters("@psCodAnalisis").Value = .CodAnalisis
                cmd.Parameters.Add(New SqlParameter("@psCodComunidad", SqlDbType.VarChar, 7))
                cmd.Parameters("@psCodComunidad").Value = IIf(.CodComunidad Is String.Empty, DBNull.Value, .CodComunidad)
                cmd.Parameters.Add(New SqlParameter("@psCodCentroCosto", SqlDbType.VarChar, 7))
                cmd.Parameters("@psCodCentroCosto").Value = .CodCentroCosto
                cmd.Parameters.Add(New SqlParameter("@pnPsoEquipajePasajero", SqlDbType.Decimal))
                cmd.Parameters("@pnPsoEquipajePasajero").Value = .PsoEquipajePasajero
                cmd.Parameters.Add(New SqlParameter("@psEstadoReserva", SqlDbType.VarChar, 1))
                cmd.Parameters("@psEstadoReserva").Value = .EstadoReserva
                cmd.Parameters.Add(New SqlParameter("@plFlgRequisitos", SqlDbType.Bit))
                cmd.Parameters("@plFlgRequisitos").Value = .FlgRequisitos
                cmd.Parameters.Add(New SqlParameter("@pdFchRetorno", SqlDbType.DateTime))
                cmd.Parameters("@pdFchRetorno").Value = .FchRetorno
                cmd.Parameters.Add(New SqlParameter("@plFlgPermiso", SqlDbType.Bit))
                cmd.Parameters("@plFlgPermiso").Value = .FlgPermiso
                cmd.Parameters.Add(New SqlParameter("@pnCodPasajero", SqlDbType.Int))
                cmd.Parameters("@pnCodPasajero").Value = .CodPasajero
                cmd.Parameters.Add(New SqlParameter("@psCodLugarReserva", SqlDbType.VarChar, 3))
                cmd.Parameters("@psCodLugarReserva").Value = .CodLugarReserva
                cmd.Parameters.Add(New SqlParameter("@psNroBoleta", SqlDbType.VarChar, 20))
                cmd.Parameters("@psNroBoleta").Value = .NroBoleta
                cmd.Parameters.Add(New SqlParameter("@psObsReserva", SqlDbType.Text))
                cmd.Parameters("@psObsReserva").Value = .ObsReserva
                cmd.Parameters.Add(New SqlParameter("@pnPctCentroCosto", SqlDbType.Int))
                cmd.Parameters("@pnPctCentroCosto").Value = .PctCentroCosto
                cmd.Parameters.Add(New SqlParameter("@psCodCentroCosto2", SqlDbType.VarChar, 7))
                cmd.Parameters("@psCodCentroCosto2").Value = .CodCentroCosto2
                cmd.Parameters.Add(New SqlParameter("@plFlgSctrSalud", SqlDbType.Bit))
                cmd.Parameters("@plFlgSctrSalud").Value = .FlgSctrSalud
                cmd.Parameters.Add(New SqlParameter("@plFlgSctrPension", SqlDbType.Bit))
                cmd.Parameters("@plFlgSctrPension").Value = .FlgSctrPension
                cmd.Parameters.Add(New SqlParameter("@plFlgExamenActitud", SqlDbType.Bit))
                cmd.Parameters("@plFlgExamenActitud").Value = .FlgExamenActitud
                cmd.Parameters.Add(New SqlParameter("@plFlgAsumeMarsa", SqlDbType.Bit))
                cmd.Parameters("@plFlgAsumeMarsa").Value = .FlgAsumeMarsa
                cmd.Parameters.Add(New SqlParameter("@plFlgPrestamo", SqlDbType.Bit))
                cmd.Parameters("@plFlgPrestamo").Value = .FlgPrestamo
                cmd.Parameters.Add(New SqlParameter("@plFlgResRetorno", SqlDbType.Bit))
                cmd.Parameters("@plFlgResRetorno").Value = .FlgResRetorno
                cmd.Parameters.Add(New SqlParameter("@plFlgNew", SqlDbType.Bit))
                cmd.Parameters("@plFlgNew").Value = .FlgNew
                cmd.Parameters.Add(New SqlParameter("@plFlgResPasajero", SqlDbType.Bit))
                cmd.Parameters("@plFlgResPasajero").Value = .FlgResPasajero
            End With
            cnx.Open()
            cmd.ExecuteNonQuery()
            lExito = True
        Catch x As SqlException
            MsgBox("Reserva (pr_ModifcarReserva) --> " & x.Message, MsgBoxStyle.Critical)
            lExito = False
        Finally
            If cnx.State = ConnectionState.Open Then
                cnx.Close()
            End If
            cmd.Parameters.Clear()
        End Try
        Return lExito
    End Function

    Public Function pb_getReserva() As DataTable
        Using dts As New DataSet()
            Dim ada As SqlDataAdapter
            Try
                cmd.Connection = cnx
                cmd.CommandType = CommandType.StoredProcedure
                cmd.CommandText = "sp_ListadeViajesRealizados"
                ada = New SqlDataAdapter(cmd)
                ada.Fill(dts, "D_Manifiesto")
            Catch ex As Exception
                Throw New Exception(ex.Message)
            End Try
            Return dts.Tables("D_Manifiesto")
        End Using
    End Function

    Public Function RecuperarReservaPorDNI(ByVal sDnir As String, ByVal sFchViaje As String) As Integer
        Dim nCod As Integer = 0
        Try
            cnx.Open()
            With cmd
                .Connection = cnx
                .CommandType = CommandType.Text
                .CommandText = "SELECT MAX(CodReserva) AS CodReserva FROM dbo.V_Reserva WITH (NOLOCK) INNER JOIN dbo.M_Pasajero WITH (NOLOCK) ON V_Reserva.CodPasajero = M_Pasajero.CodPasajero WHERE M_Pasajero.NroDocumentoId= @p_NroDocumentoId AND V_Reserva.FchViaje = @p_FchViaje "
                .Parameters.Add(New SqlParameter("@p_NroDocumentoId", SqlDbType.VarChar, 8))
                .Parameters("@p_NroDocumentoId").Value = sDnir
                .Parameters.Add(New SqlParameter("@p_FchViaje", SqlDbType.VarChar, 10))
                .Parameters("@p_FchViaje").Value = sFchViaje
                nCod = .ExecuteScalar()
            End With
        Catch myException As Exception
            MsgBox("Correlativo --> " & myException.Message, MsgBoxStyle.Critical)
            Return Nothing
        Finally
            cnx.Close()
        End Try
        Return nCod
    End Function

    Public Function TraerReserva(ByVal sCodr As Integer) As V_ReservaBE
        Dim dtr As SqlDataReader
        Dim _rBE As New V_ReservaBE
        Try
            cmd.Connection = cnx
            cmd.CommandType = CommandType.StoredProcedure
            cmd.CommandText = "pr_TraerReserva"
            cmd.Parameters.Add(New SqlParameter("@pnCodReserva", SqlDbType.Int))
            cmd.Parameters("@pnCodReserva").Value = sCodr
            cnx.Open()
            dtr = cmd.ExecuteReader
            If dtr.HasRows = True Then
                dtr.Read()
                With _rBE
                    .CodReserva = dtr("CodReserva")
                    If IsDBNull(dtr("FchReserva")) Then
                        .FchReserva = DateTime.Now
                    Else
                        .FchReserva = dtr("FchReserva")
                    End If
                    .TipPasajero = dtr("TipPasajero")
                    If IsDBNull(dtr("NomContacto")) Then
                        .NomContacto = ""
                    Else
                        .NomContacto = dtr("NomContacto")
                    End If
                    If IsDBNull(dtr("FchViaje")) Then
                        .FchViaje = DateTime.Now
                    Else
                        .FchViaje = dtr("FchViaje")
                    End If
                    .PsoPasajero = dtr("PsoPasajero")
                    .NroPrioridad = dtr("NroPrioridad")
                    .MotivoViaje = dtr("MotivoViaje")
                    .CodAnalisis = dtr("CodAnalisis")
                    If IsDBNull(dtr("CodComunidad")) Then
                        .CodComunidad = ""
                    Else
                        .CodComunidad = dtr("CodComunidad")
                    End If
                    .CodCentroCosto = dtr("CodCentroCosto")
                    .PsoEquipajePasajero = dtr("PsoEquipajePasajero")
                    .EstadoReserva = dtr("EstadoReserva")
                    .FlgRequisitos = dtr("FlgRequisitos")
                    If IsDBNull(dtr("FchRetorno")) Then
                        .FchRetorno = DateTime.Now
                    Else
                        .FchRetorno = dtr("FchRetorno")
                    End If
                    .FlgPermiso = dtr("FlgPermiso")
                    .CodPasajero = dtr("CodPasajero")
                    .CodLugarReserva = dtr("CodLugarReserva")
                    .NroBoleta = dtr("NroBoleta")
                    .ObsReserva = dtr("ObsReserva")
                    .PctCentroCosto = dtr("PctCentroCosto")
                    .CodCentroCosto2 = dtr("CodCentroCosto2")
                    .FlgSctrSalud = dtr("FlgSctrSalud")
                    .FlgSctrPension = dtr("FlgSctrPension")
                    .FlgExamenActitud = dtr("FlgExamenActitud")
                    .FlgAsumeMarsa = dtr("FlgAsumeMarsa")
                    .FlgPrestamo = dtr("FlgPrestamo")
                    If IsDBNull(dtr("FlgResRetorno")) Then
                        .FlgResRetorno = False
                    Else
                        .FlgResRetorno = dtr("FlgResRetorno")
                    End If

                    If IsDBNull(dtr("FlgNew")) Then
                        .FlgNew = False
                    Else
                        .FlgNew = dtr("FlgNew")
                    End If

                    If IsDBNull(dtr("FlgResPasajero")) Then
                        .FlgResPasajero = False
                    Else
                        .FlgResPasajero = dtr("FlgResPasajero")
                    End If
                End With
            End If
        Catch x As SqlException
            MsgBox("Reserva (pr_TraerReserva) --> " & x.Message, MsgBoxStyle.Critical)
        Finally
            If cnx.State = ConnectionState.Open Then
                cnx.Close()
            End If
            cmd.Parameters.Clear()
        End Try
        Return _rBE
    End Function
End Class
